package com.cyu.invoicing.controller;
import com.cyu.invoicing.model.bo.RestResponseBo;
import com.cyu.invoicing.model.user;
import com.cyu.invoicing.model.vo.UserVo;
import com.cyu.invoicing.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.sql.Date;
import java.util.List;

/**
 * @author 刘
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("/addUser")
    @ResponseBody
    public int addUser(@RequestBody UserVo user){
        user.setUpdatetime(new Date(System.currentTimeMillis()));
        user.setLockTime(new Date(System.currentTimeMillis()));
        userService.addUser(user);
        return 0;
    }

    @RequestMapping("/getUserList")
    @ResponseBody
    public RestResponseBo<List<UserVo>> test3(){
        RestResponseBo<List<UserVo>> result=
                new RestResponseBo<List<UserVo>>();
        result.setPayload(userService.listUser());
        return result;
    }

    @RequestMapping("/updateUserPassword")
    @ResponseBody
    public RestResponseBo<List<UserVo>> updateUserPassword(@RequestBody UserVo user){
        userService.updateUserPassword(user);
        RestResponseBo<List<UserVo>> result=
                new RestResponseBo<List<UserVo>>();
        //result.setPayload(userService.updateUserPassword(user));
        return result;
    }
}
